package com.reds.backend.controller.checkController;

import com.alibaba.fastjson2.JSON;
import com.reds.backend.pojo.Article;
import com.reds.backend.utils.adminUtils.admin.StpAdminUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.reds.backend.service.check.checkCRUDSerivce;

import java.util.Map;

@RestController
public class checkCRUDController {
    @Autowired
    checkCRUDSerivce checkCRUDSerivce;

    @PostMapping("/checkArticle/")
    public String checkArticle (@RequestParam Map<String,String> map){
        StpAdminUtil.checkRoleOr("admin","superAdmin");
        return checkCRUDSerivce.checkArticle(Integer.parseInt(map.get("id")),map.get("state"));
    }
    @PostMapping("/getAuthor/")
    public String getAuthor(@RequestParam Map<String,String> map){
        return checkCRUDSerivce.getAuthor(Integer.parseInt(map.get("id")));
    }
    @PostMapping("/deteleArticle/")
    public String deteleArticle(@RequestParam Map<String,String> map){
        return checkCRUDSerivce.deteleArticle(Integer.parseInt(map.get("id")));
    }
    @PostMapping("/updataArticle/")
    public String updataArticle(@RequestParam Map<String,String> map){
        Article article = JSON.parseObject(map.get("article"),Article.class);
        return checkCRUDSerivce.updataArticle(article,map.get("address"));
    }
}
